#ifndef HEADCOUNTER_H
#define HEADCOUNTER_H

#include "BasicType.h"
#include <opencv2/opencv.hpp>
#include <string>
#include <vector>



class HeadCounter
{
public:
	struct ColorRange
	{
		std::string name;
		cv::Scalar low;
		cv::Scalar delta;
	};

	typedef std::vector< ColorRange >	ColorRangeList;

	struct Params
	{
		int arc;
		int area;

		//ColorRange background;
		ColorRangeList colorRanges;

		Params():
			arc(),
			area()
		{
		}
	};

	static bool load(const char* filename, Params& params);

public:
    HeadCounter();
    ~HeadCounter();

	cv::Mat countHead(cv::Mat& src, int& count);
    cv::Mat countHead(cv::Mat& src, int& count, std::vector<std::vector<cv::Point> >& contours);

	bool loadParams(const char* filename);

	Params	m_params;


protected:
	

	cv::Mat buildMask(cv::Mat& src);
	cv::Mat makeForeground(cv::Mat& src);

	cv::Mat makeForeground(cv::Mat& src, double lowThresh, double highThresh, int minRadius);
	cv::Mat makeContourRectMat(cv::Mat& binMat, int minRadius);

protected:
	void drawNum(cv::Mat& mat, int count, cv::Scalar color = cv::Scalar(255, 0, 0));


	int findColorContours(cv::Mat& srcMat, cv::Scalar lowColor, cv::Scalar delta,
			std::vector<std::vector<cv::Point> >& outContours);

	int findColorContours(cv::Mat srcMat, cv::Scalar lowColor, cv::Scalar delta, int minArc, double minArea,
		std::vector<std::vector<cv::Point> >& outContours);
};

#endif // HEADCOUNTER_H
